# coding:utf-8
from __future__ import unicode_literals

from datetime import datetime
from django.contrib.auth.models import AbstractUser
from django.db import models


# Create your models here.
class UserProfile(AbstractUser):
    nick_name = models.CharField(max_length=50, verbose_name=u'昵称', default=u'')
    birday = models.DateField(verbose_name=u'生日', blank=True, null=True)
    gender = models.CharField(max_length=6, choices=(('male', u'男'), ('female', u'女')), default='female')
    adress = models.CharField(max_length=100, verbose_name=u'地址', default=u'')
    mobile = models.CharField(max_length=11, blank=True, null=True)
    image = models.ImageField(upload_to='image/%Y/%m', null=True, blank=True, default='image/defualt.png',
                              max_length=100)

    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.username


class UserEmailVerifyCode(models.Model):
    code = models.CharField(max_length=20, verbose_name=u'验证码')
    email = models.EmailField(verbose_name=u'邮箱', max_length=50)
    send_type = models.CharField(choices=(('register', '注册'), ('forget', u'找回密码')), max_length=10,
                                 verbose_name=u'注册码类型')
    send_time = models.DateTimeField(default=datetime.now, verbose_name=u'发送时间')  # 这个地方如果加上()就会生成编译时的时间

    class Meta:
        verbose_name = u'邮箱验证码'
        verbose_name_plural = verbose_name

    # def __unicode__(self):
    #     return str(self.email)

    # def __str__(self):
    #     return '{0}'.format(self.email)
    #
    # def __unicode__(self):
    #     return '{0}'.format(self.email)


class Banner(models.Model):
    title = models.CharField(max_length=100, verbose_name=u'标题')
    image = models.ImageField(upload_to='image/%Y/%m', verbose_name=u'轮播图')
    index = models.IntegerField(default=100, verbose_name=u'序号')
    url = models.URLField(max_length=200, verbose_name=u'访问地址')
    add_time = models.DateTimeField(default=datetime.now, verbose_name=u'访问时间')

    class Meta:
        verbose_name = u'轮播图'
        verbose_name_plural = verbose_name
